package com.xxxx.server.utils;

import org.apache.commons.lang3.StringUtils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 电话号码合法性校验类
 *
 * @author nathan-wang on 2020-10-18
 */
public class PhoneUtil {
    public static Boolean isPhone(String telephone){
         Pattern pattern = null;
         Matcher matcher = null;
         Boolean flag = false;
        //电话号码的正则表达式
        String str="^[1](([3|5|8][\\d])|([4][4,5,6,7,8,9])|([6][2,5,6,7])|([7][^9])|([9][1,8,9]))[\\d]{8}$";
        if (StringUtils.isNotBlank(telephone)){
             pattern = Pattern.compile(str);
             matcher = pattern.matcher(telephone);
             flag = matcher.matches();
        }
        return flag;
    }

    public static void main(String[] args) {
        System.out.println(PhoneUtil.isPhone("17721516285"));
        System.out.println(PhoneUtil.isPhone("177215X6285"));

    }
}
